说明:来自翔宇亭乐园 http://www.biye5u.com 欢迎再次光临 $name = $value; } //初始化 public function __construct(){ $this->conn=new mysqli("localhost","root","147258","empirecms"); $this->conn->set_charset('utf8'); } //销毁 public function __destruct(){ } //开始 public function getStart(){ //$param=$this->param; $param=(isset($_GET[$this->param])) ? $_GET[$this->param] : 1; return ($param-1) * $this->pagesize; } //生成SQL语句 public function getSql(){ return $this->sql . " limit " . $this->getStart() ."," .$this->pagesize . ""; //return "test"; } //获取记录 public function getRecordSet(){ $rs=$this->conn->query($this->getSql()); return $rs; } public function getPageCount(){ return $this->conn->query($this->sql)->num_rows / $this->pagesize; } //获取分页导航 public function getPageTool(){ $pagecount= round($this->getPageCount()); $param=(isset($_GET[$this->param])) ? $_GET[$this->param] : 1; if($param<=1){ echo "首页 上一页 "; }else{ echo "首页 上一页 "; } if($param>=$pagecount){ echo "下一页 尾页"; }else{ echo "下一页 尾页"; } } } header("Content-Type: text/html; charset=utf-8"); $page=new Page(); //$page->conn=new mysqli("localhost","root","147258","baoxuehao"); $page->param="page"; $page->pagesize=5; $page->sql="select * from phome_ecms_news"; $rs=$page->getRecordSet(); echo ""; while($row = $rs->fetch_assoc()){ echo ""; } echo "
".$row['id'].$row['title'] . "
"; $page->getPageTool(); ?>